package com.runfast.waimai.web.controller.cuser;

import com.runfast.common.web.entity.Result;
import com.runfast.waimai.dao.model.*;
import com.runfast.waimai.service.RunfastAccountrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ${DESCRIPTION} 客户账户变动记录
 *
 * @author chenzheng
 * @create 2018-05-22 16:48
 **/
@RestController("cuserAccountRecordController")
@RequestMapping("/server/cuserAccountRecord")
public class CuserAccountRecordController {
    @Autowired
    private RunfastAccountrecordService runfastAccountrecordService;
    /**
     * 客户账户变动记录列表带分页的
     */
    @GetMapping("/list")
    public Result list(@PageableDefault Pageable pageable, RunfastAccountrecord accountrecord){
        RunfastAccountrecordExample example=new RunfastAccountrecordExample();
        if(accountrecord!=null){
            if(accountrecord.getMobile()!=null){
                example.createCriteria().andMobileEqualTo(accountrecord.getMobile());
            }
            if(accountrecord.getCardnumber()!=null){
                example.createCriteria().andCardnumberEqualTo(accountrecord.getCardnumber());
            }
            if(accountrecord.getStartTime()!=null){
                example.createCriteria().andCreatetimeGreaterThanOrEqualTo(accountrecord.getStartTime());
            }
            if(accountrecord.getEndTime()!=null){
                example.createCriteria().andCreatetimeLessThanOrEqualTo(accountrecord.getEndTime());
            }
        }
        List<RunfastAccountrecord> list=runfastAccountrecordService.selectByExampleWithPageable(example,pageable);
        Integer total=runfastAccountrecordService.countByExample(example);
        Map<Object,Object> map=new HashMap<Object, Object>();
        map.put("list",list);
        map.put("total",total);
        return Result.ok(null,map);
    }

}
